package com.example.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.example.base.limit.IPRateLimit;

import java.util.Base64;
import java.util.List;
import com.example.base.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.example.business.service.SysImgService;
import com.example.business.entity.SysImg;
import java.io.Serializable;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 视频封面表 前端控制器
 * </p>
 *
 * @author xiong
 * @since 2024-01-26
 */

@RestController
@Api(tags = {"视频封面表的服务类"})
@RequestMapping("/sys-img")
public class SysImgController {

        @Autowired
        private SysImgService sysImgService;


        @PostMapping("/saveorupdate")
        @IPRateLimit(name = "SysImg-saveorupdate",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的更新和新增接口",notes = "视频封面表的更新和新增接口")
        public JSONObject save(@RequestBody SysImg sysImg) {
                boolean flag= sysImgService.saveOrUpdate(sysImg);
                if(flag){
                        return Result.successInfo("保存成功");
                }else {
                        return Result.errorInfo("保存失败");
                }
        }

        @DeleteMapping("/{id}")
        @IPRateLimit(name = "SysImg-del",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的删除接口",notes = "视频封面表的删除接口")
        public JSONObject delete(@PathVariable("id") Serializable id) {
                boolean flag = sysImgService.removeById(id);
                if(flag){
                        return Result.successInfo("删除成功");
                }else {
                        return Result.errorInfo("删除失败");
                }
        }

        @PostMapping("/del/batch")
        @IPRateLimit(name = "SysImg-delbatch",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的批量删除接口",notes = "视频封面表的批量删除接口")
        public JSONObject deleteBatch(@RequestBody List<Integer> ids){
                boolean flag =  sysImgService.removeByIds(ids);
                if(flag){
                        return Result.successInfo("删除成功");
                }else {
                        return Result.errorInfo("删除失败");
                }
        }

        @GetMapping("/getall")
        @IPRateLimit(name = "SysImg-getall",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的获取全部接口",notes = "视频封面表的获取全部接口")
        public JSONObject findAll() {
                List<SysImg> list= sysImgService.list();
                return Result.successInfo(list);
        }

        @GetMapping("/{id}")
        @IPRateLimit(name = "SysImg-getid",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的获取一个接口",notes = "视频封面表的获取一个接口")
        public JSONObject findOne(@PathVariable("id") Serializable id) {
                SysImg data= sysImgService.getById(id);
                return Result.successInfo(data);
        }

        @GetMapping("/page")
        @IPRateLimit(name = "SysImg-page",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "视频封面表的分页接口",notes = "视频封面表的分页接口")
        public JSONObject findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize) {
                QueryWrapper<SysImg> queryWrapper = new QueryWrapper<>();
                IPage<SysImg> page=sysImgService.page(new Page<>(pageNum, pageSize),queryWrapper);
                return Result.successInfo(page);
        }
}

